
import random
import numpy as np

import matplotlib.pyplot as plt
import matplotlib.font_manager as fm
# from proplot import rc
plt.rcParams['axes.unicode_minus'] = False  # -
plt.rcParams['font.sans-serif'] = ['SimHei']  # 用来正常显示中文标签
# rc["font.family"] = "Times New Roman"  # 统一设置字体
# rc["font.family"] = "Arial"  # 统一设置字体
# rc["axes.labelweight"] = "light" # 统一设置轴刻度标签的字体粗细
# rc["tick.labelweight"] = "bold"  # 统一设置xy轴名称的字体粗细

xpixels=400
ypixels=300
dpi=60

xinch = xpixels / dpi
yinch = ypixels / dpi
fig, axes = plt.subplots(1, 1, figsize=(xinch, yinch))


pdf_name = '3-1-a'
# pdf_name = '3-1-b'
# pdf_name = '3-2-a'
datas = [
{
    'BGL': [0.98, 0.82, 0.96, 0.99],
    'HDFS': [0.78, 0.62, 0.63, 0.54],
},
# {
#     'BGL': [0.07, 0.06, 0.08, 0.06],
#     'HDFS': [0.04, 0.023, 0.036, 0.025],
# },
# {
#     'BGL': [0.90, 0.88, 0.86, 0.81],
#     'HDFS': [0.89, 0.77, 0.65, 0.59],
# },
]

fontsize = 25
labels = ['20%', '40%', '60%', '80%']
color = ['red', 'orange', 'green', 'blue', 'cyan', 'purple', 'pink', 'coral', 'gold', 'lime', 'navy', 'teal', 'indigo']
marker = ['o', 's', '*']





for cnt, data in enumerate(datas):
    models = list(data.keys())
    performance = list(data.values())

    for i in range(len(models)):
        # zoom = 0.5 if '方法' in models[i] else 1
        value = np.array(performance[i])
        # dif = random.random()*zoom
        axes.plot(range(len(value)), value, color=color[i], linewidth=2, label=models[i], marker=marker[i])
        # axes[cnt].fill_between(range(len(value)), value-dif, value+dif, color=color[i], alpha=0.15)

    # 添加标题和标签
    # axes[cnt].set_title(titles[cnt], fontsize=fontsize)
    # axes[cnt].set_ylabel('性能', fontsize=fontsize)
    # axes.set_ylim(0, 0.2)
    axes.tick_params(labelsize=fontsize*0.9)
    if cnt == 0:
        # 显示图例
        axes.legend(fontsize=fontsize*0.8, loc='lower left', ncol=2, framealpha=0.2)
        # axes.legend(fontsize=fontsize*0.8, loc='upper left', ncol=2, framealpha=0.2)
    # if cnt == 2:
    # 修改x刻度
    axes.set_xticks(range(len(value)), labels)
    # else:
    #     # 修改x刻度
    #     axes[cnt].set_xticks([])

plt.tight_layout()
plt.grid(axis='y', linestyle='--')

# 显示图形
# plt.show()
plt.savefig(f'{pdf_name}.pdf')
plt.savefig(f'{pdf_name}.png')
plt.close()